#ifndef GAMEROOM_H
#define GAMEROOM_H

#include <QWidget>
#include<QSound>

enum class SnakeDirect
{
    UP=0,
    DOWN,
    LEFT,
    RIGHT
};

class gameroom : public QWidget
{
    Q_OBJECT
public:
    explicit gameroom(QWidget *parent = nullptr);

    //重写绘图事件
    void paintEvent(QPaintEvent *event);

    void moveUp();
    void moveDown();
    void moveLeft();
    void moveRight();

    bool checkFail();

    void createNewFood();

    void  setTimeout(int timeout){moveTime=timeout;}

private:
    const int KSnakeNodeWidth = 20;
    const int KSnakeNodeHeight = 20;

    const int KDefaultTimeout = 200;//移动速度

    QList<QRectF> snakeList;//表示链表
    QRectF foodRect;//食物
    SnakeDirect  moveDirect = SnakeDirect::UP;//默认移动方向
    QTimer *timer;//定时器

    bool  isGameStart = false;//游戏的开始


    QSound *sound;

    int moveTime = KDefaultTimeout;
};

#endif // GAMEROOM_H
